<template>
  <div style="padding: 10px">
    <d-table
      :data="tableData"
      :columns="columns"
      stripe
      :showPagination="false"
      :default-sort="{ prop: 'date', order: 'descending' }">
      <template #header>普通表头自定义</template>
      <template #yjHeader>一级表头自定义</template>
      <template #erjHeader><span style="color: red">二级表头自定义</span></template>
      <template #sjHeader>三级表头自定义</template>
      <template #head="{ row, column, index }">
        我是自定义{{ row[column.prop] }}-{{ index }}
      </template>
      <template #city="{ row, column, index }">自定义-{{ row[column.prop] }}-{{ index }}</template>
    </d-table>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  const tableData = [
    {
      date: '2016-05-03',
      name: 'Tom',
      head: '数据',
      city: 'Los Angeles',
      address: 'No. 189, Grove St, Los Angeles'
    },
    {
      date: '2016-05-02',
      name: 'Tom',
      city: 'Los Angeles',
      address: 'No. 189, Grove St, Los Angeles'
    },
    {
      date: '2016-05-04',
      name: 'Tom',
      city: 'Los Angeles',
      address: 'No. 189, Grove St, Los Angeles'
    }
  ]
  const columns = ref([
    {
      label: '日期',
      prop: 'date',
      sortable: true
    },
    {
      label: '自定义',
      prop: 'head',
      headerSlot: 'header',
      slot: 'head'
    },
    {
      label: '国籍',
      headerSlot: 'yjHeader',
      children: [
        {
          label: '姓名',
          prop: 'name'
        },
        {
          label: '信息',
          headerSlot: 'erjHeader',
          children: [
            {
              label: '城市',
              headerSlot: 'sjHeader',
              prop: 'city',
              slot: 'city'
            },
            {
              label: '地址',
              prop: 'address'
            }
          ]
        }
      ]
    }
  ])
</script>
